<?php

namespace Ledger;

use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;

class Module {

	public function getConfig() {
		return include __DIR__ . '/config/module.config.php';
	}

	public function getAutoloaderConfig() {
		return array(
			'Zend\Loader\StandardAutoloader' => array(
				'namespaces' => array(
					__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
				),
			),
		);
	}

	public function onBootstrap(MvcEvent $e) {
		// enable MVC routing for this modulea
//        (new ModuleRouteListener())->attach(
//            $e->getApplication()->getEventManager());

		$eventManager				 = $e->getApplication()->getEventManager();
		$moduleRouteListener = new ModuleRouteListener();
		$moduleRouteListener->attach($eventManager);
	}

	public function getServiceConfig() {
		return array(
			'factories'					 => array(
				'Db\Accounts'	 => function ($sm) {
					$dbAdapter					 = $sm->get('Zend\Db\Adapter\Adapter');
					$resultSetPrototype	 = new ResultSet();
					$resultSetPrototype->setArrayObjectPrototype(new Model\Account());
					
					return new TableGateway('accounts', $dbAdapter, null, $resultSetPrototype);
				},
			),
		);
	}

}
